﻿/**
作者：常亮
时间：209-11-19
功能：实现用户增加
**/
var ArrList = new Array();
function ShowMain() {
    GetUser();
}
//获取"信息"
function GetUser() {
    var url = encodeURI(SBasePath + '/action/UsersManage/GetUserDept.aspx');
    var pars = encodeURI('');
    var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sGetUser, onFailure: fGetUser });
}
//获取"信息"成功
function sGetUser(o) {
    ArrList = MapAdmin_UserDept(o);
    ShowContent();
}
function fGetUser() {

}

//提交
function sbmt() {
    document.getElementById("typename").value = document.getElementById('bm').options[document.getElementById('bm').selectedIndex].text;
    document.getElementById("typeid").value = document.getElementById("bm").value;

    if (CheckForm()) {
        var url = encodeURI(SBasePath + '/action/usersmanage/UsersAdd.aspx');
        var myAjax = new Ajax.Request(url, { method: 'post', parameters: Form.serialize("formsubmit"), onComplete: sFormSubmit, onFailure: fFormSubmit });
    }
};

//提交成功
var sFormSubmit = function(o) {
    var root = o.responseXML.documentElement;
    var OutputFlag = GetXmlData(root, "Value");

    if (OutputFlag == "true") {
        MsgDlgLocal('保存成功！');
    }

};

//提交失败
var fFormSubmit = function(o) {
};


var CheckForm = function() {

    var fobj = $("formsubmit");

    if (Trim(fobj.UserName.value) == "") {
        $("UserNamediv").style.display = "";
        return false;
    }
    else {
        $("UserNamediv").style.display = "none";
    }


    if (Trim(fobj.Pwd.value) == "") {
        $("fPwd").style.display = "";
        return false;
    }
    else {
            $("fPwd").style.display = "none";
            if (GetStrLength(Trim(fobj.Pwd.value)) < 6) {
                $("Pwdxy").style.display = ""
                return false;
            } else {
                $("Pwdxy").style.display = "none"
            }

            if (GetStrLength(Trim(fobj.Pwd.value)) > 20) {
                $("Pwddy").style.display = ""
                return false;
            } else {
            $("Pwddy").style.display = "none"
            }
    }
    if (document.getElementById("typeid").value == "0") {
        MsgDlg("请选择组织机构！");
        return false;
    }

    if (Trim(fobj.RPwd.value) != Trim(fobj.Pwd.value)) {
        $("sPwd").style.display = "";
        return false;
    } else {
        $("sPwd").style.display = "none";
    }

    if (Trim(fobj.DisName.value) == "") {
        $("DisplayName").style.display = "";
        return false;
    } else {
        $("DisplayName").style.display = "none";
    }
    return true;
};

function OutName() {
    if (document.getElementById("UserName").value == "") {
      $("UserNamediv").style.display = "";
        return false;
    } else {
        $("UserNamediv").style.display = "none";
        var url = encodeURI(SBasePath + '/action/UsersManage/UsersExist.aspx');
        var pars = encodeURI("?UserName="+document.getElementById("UserName").value);
        var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sFormSubmitExist, onFailure: fFormSubmitExist });
    }
}
function sFormSubmitExist(o) {
   
    var root = o.responseXML.documentElement;
    
    var OutputFlag = GetXmlData(root, "Value");
    if (OutputFlag == "True") {
        $("UserNameExist").style.display = "";
        return false;
    }
    else {
        $("UserNameExist").style.display = "none";
           return true;
    }
   
}

function fFormSubmitExist()
{ 

}

function ShowContent() {
    var str = "";
    str += '<form id="formsubmit">';
    str += '<input type="hidden" id="typename" name="typename" value=""/>';
    str += '<input type="hidden" id="typeid" name="typeid" value=""/>';
        str+='<table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">';
        str+='<tr>';
        str+='    <td height="30">';
        str+='        <table width="100%" border="0" cellspacing="0" cellpadding="0">';
        str+='            <tr>';
        str+='                <td width="15" height="30" class="tab03">';
        str+='                </td>';
        str+='                <td class="tab05">';
        str+='                    <div class="title1" style="padding-top: 2px">';
        str+='                        <img src="../../img/1.gif" height="20" width="19" />添加用户</div>';
        str+='                </td>';
        str+='                <td width="14" class="tab07"></td>';
        str+='            </tr>';
        str+='        </table>';
        str+='    </td>';
        str+='</tr>';
        str+='<tr>';
        str+='    <td>';
        str+='        <table width="100%" border="0" cellspacing="0" cellpadding="0">';
        str+='            <tr>';
        str+='                <td width="9" class="tab12"></td>';
        str+='                <td bgcolor="#f3ffe3">';
        str+='                    <table width="100%" border="0" cellspacing="0" cellpadding="0">';
        str+='                        <tr>';
        str+='                            <td class="k_hui">';
        str+='                                <table width="97%" border="0" cellspacing="0" cellpadding="0" align="center">';
        str+= '                                    <tr height="38">';
        str+='                                        <td height="30" width="12%" style="padding-left: 5px">';
        str+='                                            用户名：';
        str+='                                        </td>';
        str+='                                        <td width="25%">';
        str += '                                            <input type="text" name="UserName" id="UserName" class="wbk"  onblur="OutName()" />';
        str+='                                        </td>';
        str+='                                        <td width="52%" class="zw">';
        str+= '                                            <div alght="right" class="clew" id="UserNamediv" style="display:none">';
        str+='                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />用户名不能为空！</div>';
        str+= '                                            <div alght="right" class="clew" id="UserNameExist" style="display:none">';
        str+='                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />用户名已存在！</div>';
        str+='                                        </td>';
        str+='                                    </tr>';
        str+= '                                    <tr height="38">';
        str+='                                        <td height="30" width="12%" style="padding-left: 5px">';
        str+='                                            密&nbsp;&nbsp;码：';
        str+='                                        </td>';
        str+='                                        <td widht="25%">';
        str+='                                            <input type="password" name="Pwd" id="Pwd" class="wbk" />';
        str+='                                        </td>';
        str+='                                        <td width="52%" class="zw">';
        str+= '                                            <div alght="right" class="clew" id="fPwd" style="display:none">';
        str+='                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />密码不能为空！</div>';
        str += '                                            <div alght="right" class="clew" id="Pwdxy" style="display:none">';
        str += '                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />密码不能小于6个字符！</div>';
        str += '                                            <div alght="right" class="clew" id="Pwddy" style="display:none">';
        str += '                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />密码不能大于20个字符！</div>';
        str+='                                        </td>';
        str+='                                    </tr>';
        str+= '                                    <tr height="38">';
        str+='                                        <td height="30" width="12%" style="padding-left: 5px">';
        str+='                                            确认密码：';
        str+='                                        </td>';
        str+='                                        <td widht="25%">';
        str+='                                            <input type="password" name="RPwd" id="RPwd" class="wbk" />';
        str+='                                        </td>';
        str+='                                        <td width="52%" class="zw">';
        str+= '                                            <div alght="right" class="clew" id="SPwd" style="display:none">';
        str+='                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />两次密码不一致！</div>';
        str+='                                        </td>';
        str+='                                   </tr>';
        str+= '                                    <tr height="38">';
        str+='                                        <td height="30" width="12%" style="padding-left: 5px">';
        str+='                                            真实姓名：';
        str+='                                        </td>';
        str+='                                        <td widht="25%">';
        str+='                                            <input type="text" name="DisName" id="DisName" class="wbk" />';
        str+='                                        </td>';
        str+='                                        <td width="52%" class="zw">';
        str += '                                            <div alght="right" class="clew" id="DisplayName" style="display:none">';
        str+='                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />真实姓名不能为空！</div>';
        str+='                                        </td>';
        str += '                                   </tr>';
                str+= '                                    <tr height="38">';
        str+='                                        <td height="30" width="12%" style="padding-left: 5px">';
        str+='                                            所属部门：';
        str+='                                        </td>';
        str += '                                        <td widht="25%">';
        str+='<select id="bm" name="bm">'
        str += '<option value="0" selected>组织机构</option>';
        for (var i = 0; i < ArrList.length; i++) {
            str += '              <option value="' + ArrList[i].DeptID + '">' + ArrList[i].DeptName + '</option>';
        }

        str += '                                        </td>';
        
        str+='                                        <td width="52%" class="zw">';
        str += '                                            <div alght="right" class="clew" id="DisplayName" style="display:none">';
        str+='                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />真实姓名不能为空！</div>';
        str+='                                        </td>';
        str += '                                   </tr>';
        str += '                                    <tr height="38">';
        str+='                                        <td height="30" width="12%" style="padding-left: 5px">';
        str+='                                            办公电话：';
        str+='                                        </td>';
        str+='                                        <td widht="25%">';
        str+='                                            <input type="text" name="tel" id="tel" class="wbk" />';
        str+='                                        </td>';
        str+='                                        <td width="52%" class="zw">';
        str+='                                        </td>';
        str+='                                    </tr>';
        str+= '                                    <tr height="38">';
        str+='                                        <td height="30" width="12%" style="padding-left: 5px">';
        str+='                                            移动电话：';
        str+='                                        </td>';
        str+='                                        <td widht="25%">';
        str+='                                            <input type="text" name="mobile" id="mobile" class="wbk" />';
        str+='                                        </td>';
        str+='                                        <td width="52%" class="zw">';
        str+='                                        </td>';
        str+='                                    </tr>';
        str += '                                    <tr height="38">';
        str+='                                        <td height="30" width="12%" style="padding-left: 5px">';
        str+='                                            用户地址：';
        str+='                                        </td>';
        str+='                                        <td widht="25%">';
        str+='                                            <input type="text" name="address" id="address" style="height: 18px; width: 250px; border: solid 1px #cadcb2;" />';
        str+='                                        </td>';
        str+='                                        <td width="52%" class="zw">';
        str+='                                        </td>';
        str+='                                    </tr>';
        str += '                                    <tr height="38">';
        str+='                                        <td height="30" width="12%" style="padding-left: 5px">';
        str+='                                            用户简介：';
        str+='                                        </td>';
        str+='                                        <td widht="25%">';
        str+='                                            <textarea name="yhjj" id="yhjj" cols="50" rows="11" style="height: 100px; width: 250px; border: solid 1px #cadcb2;"></textarea>';
        str+='                                        </td>';
        str+='                                        <td width="52%" class="zw">';
        str+='                                        </td>';
        str+='                                    </tr>';
        str += '                                    <tr height="38">';
        str+='                                        <td colspan="2" style="padding-left: 25px" height="30">';
        str+='                                             <input name="提交" type="button" class="bg_g" style="height: 22px; width: 60px; border: solid 1px #cadcb2;"value="提交" onclick="sbmt()" />';
        str+='                                            &nbsp;&nbsp;<input name="重置" type="reset" class="bg_g" style="height: 22px; width: 60px;border: solid 1px #cadcb2;" value="重置" />';
        str+='                                        </td>';
        str+='                                        <td width="52%" class="zw">';
        str+='                                        </td>';
        str+='                                    </tr>';
        str+='                                </table>';
        str+='                             </td>';
        str+='                        </tr>';
        str+='                    </table>';
        str+='                </td>';
        str+='                <td width="9" class="tab16">';
        str+='                </td>';
        str+='            </tr>';
        str+='        </table>';
        str+='    </td>';
        str+='</tr>';
        str+='<tr>';
        str+='    <td height="29">';
        str+='        <table width="100%" border="0" cellspacing="0" cellpadding="0">';
        str+='            <tr>';
        str+='                <td width="15" height="29" class="tab20">';
        str+='                </td>';
        str+='                <td class="tab21">';
        str+='                    &nbsp;';
        str+='                </td>';
        str+='                <td width="14" class="tab22">';
        str+='                </td>';
        str+='            </tr>';
        str+='        </table>';
        str+='    </td>';
        str+='</tr>';
        str += '</table>';
        str += '</form>';
        $("UsersAdd").innerHTML=str;
}